package cn.factorybox.item.utils;

import cn.factorybox.model.entity.DeviceData;
import cn.factorybox.model.entity.JudgeValue;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-03-24 23:03
 */
public class JudgeAppData {

    public static List<Map<String,Object>> formatData(DeviceData deviceData, List<JudgeValue> list,int type) {
        List<Map<String,Object>> lists = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            Map<String,Object> map = new HashMap<>();
            lists.add(map);
        }
        getStyle(deviceData,lists,list,type);
        return lists;
    }

    public static void getStyle(DeviceData deviceData,List<Map<String,Object>> lists, List<JudgeValue> list,int type) {
        if (deviceData.getfTemperature() != null) {
            if (type == 0) {
                judgeTemperature_indoor(deviceData.getfTemperature(),lists.get(0),list.get(0));
                judgeHumidity_indoor(deviceData.getfHumidity(),lists.get(1),list.get(1));
                judgePressure_indoor(deviceData.getfPressure(),lists.get(2),list.get(2));
                judgeExhaust_indoor(deviceData.getfExhaust(),lists.get(3),list.get(3));
                judgePM_indoor(deviceData.getfPm(),lists.get(4),list.get(4));
                judgeCO2_indoor(deviceData.getfCarbonDioxide(),lists.get(5),list.get(5));
                judgeTVOC_indoor(deviceData.getfTvoc(),lists.get(6),list.get(6));
            }else if (type == 1) {
                judgeTemperature_exper(deviceData.getfTemperature(),lists.get(0),list.get(0));
                judgeHumidity_exper(deviceData.getfHumidity(),lists.get(1),list.get(1));
                judgePressure_exper(deviceData.getfPressure(),lists.get(2),list.get(2));
                judgeExhaust_exper(deviceData.getfExhaust(),lists.get(3),list.get(3));
                judgePM_exper(deviceData.getfPm(),lists.get(4),list.get(4));
                judgeCO2_exper(deviceData.getfCarbonDioxide(),lists.get(5),list.get(5));
                judgeTVOC_exper(deviceData.getfTvoc(),lists.get(6),list.get(6));
            }else if (type == 2) {
                judgeTemperature_outdoor(deviceData.getfTemperature(),lists.get(0),list.get(0));
                judgeHumidity_outdoor(deviceData.getfHumidity(),lists.get(1),list.get(1));
                judgePressure_outdoor(deviceData.getfPressure(),lists.get(2),list.get(2));
                judgeExhaust_outdoor(deviceData.getfExhaust(),lists.get(3),list.get(3));
                judgePM_outdoor(deviceData.getfPm(),lists.get(4),list.get(4));
                judgeCO2_outdoor(deviceData.getfCarbonDioxide(),lists.get(5),list.get(5));
                judgeTVOC_outdoor(deviceData.getfTvoc(),lists.get(6),list.get(6));
            }
        }
    }

    /******************************室内判断*****************************/

    /**
     * 判断温度
     * @param m 温度值
     */
    public static void judgeTemperature_indoor(double m, Map<String,Object> map, JudgeValue jv1) {
        String rank = "";
        if (m >= jv1.getYouxiuMin() && m <= jv1.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv1.getLianghaoMin1() && m < jv1.getLianghaoMax1()) || (m > jv1.getLianghaoMin2() && m <= jv1.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv1.getYibanMin1() && m < jv1.getYibanMax1()) || (m > jv1.getYibanMin2() && m <= jv1.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv1.getWeixianMin() || m > jv1.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","温度");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断湿度
     * @param m 湿度值
     */
    public static void judgeHumidity_indoor(double m, Map<String,Object> map, JudgeValue jv2) {
        String rank = "";
        if (m >= jv2.getYouxiuMin() && m <= jv2.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv2.getLianghaoMin1() && m < jv2.getLianghaoMax1()) || (m > jv2.getLianghaoMin2() && m <= jv2.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv2.getYibanMin1() && m < jv2.getYibanMax1()) || (m > jv2.getYibanMin2() && m <= jv2.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv2.getWeixianMin() || m > jv2.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","湿度");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断室内压强
     * @param m 室内压强
     */
    public static void judgePressure_indoor(double m, Map<String,Object> map, JudgeValue jv3) {
        DecimalFormat df = new DecimalFormat("0.0");
        m = Double.valueOf(df.format(m));
        String rank = "";
        if (m >= jv3.getYouxiuMin() && m <= jv3.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv3.getLianghaoMin1() && m < jv3.getLianghaoMax1()) || (m > jv3.getLianghaoMin2() && m <= jv3.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv3.getYibanMin1() && m < jv3.getYibanMax1()) || (m > jv3.getYibanMin2() && m <= jv3.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv3.getWeixianMin() || m > jv3.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","压差");
        map.put("value",m);
        map.put("rank",rank);
    }


    /**
     * 判断排气量
     * @param m 排气量
     */
    public static void judgeExhaust_indoor(double m, Map<String,Object> map, JudgeValue jv4) {
        String rank = "";
        if (m >= jv4.getYouxiuMin() && m <= jv4.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv4.getLianghaoMin1() && m < jv4.getLianghaoMax1()) || (m > jv4.getLianghaoMin2())) {
            rank = "良好";
        } else if (m >= jv4.getYibanMin1() && m < jv4.getYibanMax1()) {
            rank = "一般";
        } else if (m >= jv4.getWeixianMin() && m < jv4.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","换气次数");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断PM2.5
     * @param m PM2.5
     */
    public static void judgePM_indoor(double m, Map<String,Object> map, JudgeValue jv5) {
        String rank = "";
        if (m >= jv5.getYouxiuMin() && m <= jv5.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv5.getLianghaoMin1() && m <= jv5.getLianghaoMax1()){
            rank = "良好";
        } else if (m > jv5.getYibanMin1() && m <= jv5.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv5.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","PM2.5");
        map.put("value",m);
        map.put("rank",rank);
    }

    public static void judgeCO2_indoor(double m, Map<String,Object> map, JudgeValue jv6) {
        String rank = "";
        if (m >= jv6.getYouxiuMin() && m <= jv6.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv6.getLianghaoMin1() && m <= jv6.getLianghaoMax1()) {
            rank = "良好";
        } else if (m > jv6.getYibanMin1() && m <= jv6.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv6.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","CO₂");
        map.put("value",m);
        map.put("rank",rank);
    }

    public static void judgeTVOC_indoor(double m, Map<String,Object> map, JudgeValue jv7) {
        String rank = "";
        if (m >= jv7.getYouxiuMin() && m <= jv7.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv7.getLianghaoMin1() && m <= jv7.getLianghaoMax1()) {
            rank = "良好";
        } else if (m > jv7.getYibanMin1() && m <= jv7.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv7.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","TVOC");
        map.put("value",m);
        map.put("rank",rank);
    }



/******************************实验室判断****************************/

    /**
     * 判断温度
     * @param m 温度值
     */
    public static void judgeTemperature_exper(double m, Map<String,Object> map, JudgeValue jv1) {
        String rank = "";
        if (m >= jv1.getYouxiuMin() && m <= jv1.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv1.getLianghaoMin1() && m < jv1.getLianghaoMax1()) || (m > jv1.getLianghaoMin2() && m <= jv1.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv1.getYibanMin1() && m < jv1.getYibanMax1()) || (m > jv1.getYibanMin2() && m <= jv1.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv1.getWeixianMin() || m > jv1.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","温度");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断湿度
     * @param m 湿度值
     */
    public static void judgeHumidity_exper(double m, Map<String,Object> map, JudgeValue jv2) {
        String rank = "";
        if (m >= jv2.getYouxiuMin() && m <= jv2.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv2.getLianghaoMin1() && m < jv2.getLianghaoMax1()) || (m > jv2.getLianghaoMin2() && m <= jv2.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv2.getYibanMin1() && m < jv2.getYibanMax1()) || (m > jv2.getYibanMin2() && m <= jv2.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv2.getWeixianMin() || m > jv2.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","湿度");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断室内压强
     * @param m 室内压强
     */
    public static void judgePressure_exper(double m, Map<String,Object> map, JudgeValue jv3) {
        DecimalFormat df = new DecimalFormat("0.0");
        m = Double.valueOf(df.format(m));
        String rank = "";
        if (m >= jv3.getYouxiuMin()) {
            rank = "优秀";
        } else if (m >= jv3.getLianghaoMin1() && m < jv3.getLianghaoMax1()) {
            rank = "良好";
        } else if (m >= jv3.getYibanMin1() && m < jv3.getYibanMax1()) {
            rank = "一般";
        } else if (m < jv3.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","压差");
        map.put("value",m);
        map.put("rank",rank);
    }


    /**
     * 判断排气量
     * @param m 排气量
     */
    public static void judgeExhaust_exper(double m, Map<String,Object> map, JudgeValue jv4) {
        String rank = "";
        if (m >= jv4.getYouxiuMin() && m <= jv4.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv4.getLianghaoMin1() && m < jv4.getLianghaoMax1()) || (m > jv4.getLianghaoMin2())) {
            rank = "良好";
        } else if (m >= jv4.getYibanMin1() && m < jv4.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv4.getWeixianMin() && m < jv4.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","换气次数");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断PM2.5
     * @param m PM2.5
     */
    public static void judgePM_exper(double m, Map<String,Object> map, JudgeValue jv5) {
        String rank = "";
        if (m >= jv5.getYouxiuMin() && m <= jv5.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv5.getLianghaoMin1() && m <= jv5.getLianghaoMax1()){
            rank = "良好";
        } else if (m > jv5.getYibanMin1() && m <= jv5.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv5.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","PM2.5");
        map.put("value",m);
        map.put("rank",rank);
    }

    public static void judgeCO2_exper(double m, Map<String,Object> map, JudgeValue jv6) {
        String rank = "";
        if (m >= jv6.getYouxiuMin() && m <= jv6.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv6.getLianghaoMin1() && m <= jv6.getLianghaoMax1()) {
            rank = "良好";
        } else if (m > jv6.getYibanMin1() && m <= jv6.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv6.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","CO₂");
        map.put("value",m);
        map.put("rank",rank);
    }

    public static void judgeTVOC_exper(double m, Map<String,Object> map, JudgeValue jv7) {
        String rank = "";
        if (m >= jv7.getYouxiuMin() && m <= jv7.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv7.getLianghaoMin1() && m <= jv7.getLianghaoMax1()) {
            rank = "良好";
        } else if (m > jv7.getYibanMin1() && m <= jv7.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv7.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","TVOC");
        map.put("value",m);
        map.put("rank",rank);
    }

/************************室外判断*************************/

    /**
     * 判断温度
     * @param m 温度值
     */
    public static void judgeTemperature_outdoor(double m, Map<String,Object> map, JudgeValue jv1) {
        String rank = "";
        if (m >= jv1.getYouxiuMin() && m <= jv1.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv1.getLianghaoMin1() && m < jv1.getLianghaoMax1()) || (m > jv1.getLianghaoMin2() && m <= jv1.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv1.getYibanMin1() && m < jv1.getYibanMax1()) || (m > jv1.getYibanMin2() && m <= jv1.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv1.getWeixianMin() || m > jv1.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","温度");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断湿度
     * @param m 湿度值
     */
    public static void judgeHumidity_outdoor(double m, Map<String,Object> map, JudgeValue jv2) {
        String rank = "";
        if (m >= jv2.getYouxiuMin() && m <= jv2.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv2.getLianghaoMin1() && m < jv2.getLianghaoMax1()) || (m > jv2.getLianghaoMin2() && m <= jv2.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv2.getYibanMin1() && m < jv2.getYibanMax1()) || (m > jv2.getYibanMin2() && m <= jv2.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv2.getWeixianMin() || m > jv2.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","湿度");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断室内压强
     * @param m 室内压强
     */
    public static void judgePressure_outdoor(double m, Map<String,Object> map, JudgeValue jv3) {
        DecimalFormat df = new DecimalFormat("0.0");
        m = Double.valueOf(df.format(m));
        String rank = "";
        if (m >= jv3.getYouxiuMin() && m <= jv3.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv3.getLianghaoMin1() && m < jv3.getLianghaoMax1()) || (m > jv3.getLianghaoMin2() && m <= jv3.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv3.getYibanMin1() && m < jv3.getYibanMax1()) || (m > jv3.getYibanMin2() && m <= jv3.getYibanMax2())) {
            rank = "一般";
        } else if (m < jv3.getWeixianMin() || m > jv3.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","压差");
        map.put("value",m);
        map.put("rank",rank);
    }


    /**
     * 判断排气量
     * @param m 排气量
     */
    public static void judgeExhaust_outdoor(double m, Map<String,Object> map, JudgeValue jv4) {
        String rank = "";
        if (m >= jv4.getYouxiuMin() && m <= jv4.getYouxiuMax()) {
            rank = "优秀";
        } else if ((m >= jv4.getLianghaoMin1() && m < jv4.getLianghaoMax1()) || (m > jv4.getLianghaoMin2() && m <= jv4.getLianghaoMax2())) {
            rank = "良好";
        } else if ((m >= jv4.getYibanMin1() && m < jv4.getYibanMax1()) || (m > jv4.getYibanMin2() && m <= jv4.getYibanMax2())) {
            rank = "一般";
        } else if (m >= 0 && m < jv4.getWeixianMin() || m > jv4.getWeixianMax()) {
            rank = "不适";
        }
        map.put("type","换气次数");
        map.put("value",m);
        map.put("rank",rank);
    }

    /**
     * 判断PM2.5
     * @param m PM2.5
     */
    public static void judgePM_outdoor(double m, Map<String,Object> map, JudgeValue jv5) {
        String rank = "";
        if (m >= jv5.getYouxiuMin() && m <= jv5.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv5.getLianghaoMin1() && m <= jv5.getLianghaoMax1()){
            rank = "良好";
        } else if (m > jv5.getYibanMin1() && m <= jv5.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv5.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","PM2.5");
        map.put("value",m);
        map.put("rank",rank);
    }

    public static void judgeCO2_outdoor(double m, Map<String,Object> map, JudgeValue jv6) {
        String rank = "";
        if (m >= jv6.getYouxiuMin() && m <= jv6.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv6.getLianghaoMin1() && m <= jv6.getLianghaoMax1()) {
            rank = "良好";
        } else if (m > jv6.getYibanMin1() && m <= jv6.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv6.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","CO₂");
        map.put("value",m);
        map.put("rank",rank);
    }

    public static void judgeTVOC_outdoor(double m, Map<String,Object> map, JudgeValue jv7) {
        String rank = "";
        if (m >= jv7.getYouxiuMin() && m <= jv7.getYouxiuMax()) {
            rank = "优秀";
        } else if (m > jv7.getLianghaoMin1() && m <= jv7.getLianghaoMax1()) {
            rank = "良好";
        } else if (m > jv7.getYibanMin1() && m <= jv7.getYibanMax1()) {
            rank = "一般";
        } else if (m > jv7.getWeixianMin()) {
            rank = "不适";
        }
        map.put("type","TVOC");
        map.put("value",m);
        map.put("rank",rank);
    }
}
